import datetime
import json
import time
from lib.apis import aep_device_event


def query_event_report(appKey='pUxUqtQiPf2', appSecret='OFf8fLb3Ou',masterKey='491bad06fffe4269a2152210e6a5bd27',productId=17048069, deviceId='17048069123456'):
    # 开始时间为今天的零点的时间戳
    startTime = int(time.mktime(datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0).timetuple())) * 1000
    # 结束时间为今天的24点的时间戳
    endTime = int(time.mktime(datetime.datetime.now().replace(hour=23, minute=59, second=59, microsecond=999999).timetuple())) * 1000
    body = {
        "productId": productId,
        "deviceId": deviceId,
        "startTime": startTime,
        "endTime": endTime,
        "pageSize": 10
    }
    # body转成json字符串
    body_json = json.dumps(body)
    
    result = aep_device_event.QueryDeviceEventList(appKey, appSecret, masterKey, body_json)
    # 将reuslt转成json对象
    result_json = json.loads(result)
    return result_json


# if __name__ == '__main__':
#     query_event_report()